import tkinter
import tkinter.messagebox
import random
import threading
import itertools
import time
root = tkinter.Tk()
root.title('随机提问')
root.geometry('260x180+400+300')
root.resizable(False, False)
def closeWindow():
    root.flag=False
    time.sleep(0.1)
    root.destroy()
root.protocol("WM_DELETE_WINDOW", closeWindow)
students=['徐','小鸡','王刚','叶子','小军','红花']
root.flag=False
def switch():
    root.flag=True
    t=students[:]
    random.shuffle(t)
    t=itertools.cycle(t)
    while root.flag:
        lbFirst['text']=lbSecond['text']
        lbSecond['text']=lbThird['text']
        lbThird['text']=next(t)
        time.sleep(0.1)
def btnStartClick():
    t=threading.Thread(target=switch)
    t.start()
    btnStart['state']='disabled'
    btnStop['state']='normal'
btnStart=tkinter.Button(root,
                 text='开始',
                 command=btnStartClick)
btnStart.place(x=30,y=10,width=80,height=20)
def btnStopClick():
    root.flag=False
    time.sleep(0.3)
    tkinter.messagebox.showinfo('恭喜',
                       '本次中奖：'+lbSecond['text'])
    btnStart['state']='normal'
    btnStop['state']='disabled'
btnStop=tkinter.Button(root,
                 text='停止',
                 command=btnStopClick)
btnStop['state']='disabled'
btnStop.place(x=150,y=10,width=80,height=20)
lbFirst=tkinter.Label(root,text='')
lbFirst.place(x=80,y=60,width=100,height=20)
lbSecond=tkinter.Label(root,text='')
lbSecond['fg']='red'
lbSecond.place(x=80,y=90,width=100,height=20)
lbThird=tkinter.Label(root,text='')
lbThird.place(x=80,y=120,width=100,height=20)
root.mainloop()